<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .root {
        background-color: red;
    }

    .first-com {
        background-color: aquamarine;
    }
</style>

<body>
    <div id="app">
        <div class="root">
            {{msg}}

        </div>

        <first-com :msg="msg" @change="msg=$event"></first-com>
    </div>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <script>
        //根组件
        var app = Vue.createApp({
            data: function () {
                return {
                    msg: '我是根组件中的msg',
                    person: {
                        name: 'Veronica',
                        company: 'Veridian Dynamics'
                    }
                }
            }
        });
        //全局注册组件
        app.component('FirstCom', {
            template: `
                <div class='first-com'>
                    <input type="text" :value="msg" @input="onInput">
                    {{msg}}
                </div>
            `,
            props: ['msg'],  //property
            methods: {
                onInput(e) {
                    //emit(发射)-on(监听)
                    //$emit('事件名',事件对象)
                    this.$emit('change', e.target.value);
                }
            },
        })




        app.mount('#app')
    </script>
</body>

</html>